package org.testfire.translator.watij.commands;

import org.testfire.model.commandtypes.VoidCommandType;
import org.testfire.model.TestsetType;
import org.testfire.translator.TestFireTranslator;

/**
 * Created by IntelliJ IDEA.
 * User: granum
 * Date: Sep 2, 2007
 * Time: 3:52:34 PM
 *
 */
public class VoidCommandToWatijTranslator<T> implements TestFireTranslator<VoidCommandType>
{

    /**
     * Will return a syntactically correct Java class, ready to be written out to a java file with the name
     * testset.getName() + ".java" and compiled.
     * @return The source code for a valid java class, containing all test cases.
     */
    public Object translate( TestsetType testset, VoidCommandType command )
    {
        StringBuilder buf = new StringBuilder( );
        buf.append(String.format("%1$s(", command.getName()));
        for(String key : command.getParameters().keySet()){
            buf.append( command.getParameter( key ).toArgumentString() ).append( ", ");
        }
        if(command.getParameters().size() > 0)
        {
            buf.delete( buf.length() - 2, buf.length());
        }
        buf.append(  ")" );

        String x = buf.toString();
        buf = new StringBuilder();
        buf.append( "%1$s");
        buf.append(x);
        return buf.toString();
    }
}